package com.cj.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cj.models.UserCoinModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface CoinMapper extends BaseMapper<UserCoinModel> {

    @Update("update user_coin set coin=coin-#{coin},version=version+1 where coin>#{coin} and username=#{username} ")
    public int transferFrom(@Param("username") String username, @Param("coin") int coin);

    @Update("update user_coin set coin=coin+#{coin},version=version+1 where username=#{username} ")
    public int transferTo(@Param("username") String username,@Param("coin") int coin);

    @Update("update user_coin set version = version+1 where username=#{username} and version=#{version}")
    public int updateVersion(@Param("username")String username,@Param("version") int version);

    @Select("select sleep(#{second})")
    public int waitSecond(@Param("second") int second);
}
